package io.renren.modules.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.admin.dao.CourseVideoDao;
import io.renren.modules.admin.entity.CourseVideoEntity;
import io.renren.modules.admin.service.CourseVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("courseVideoService")
public class CourseVideoServiceImpl extends ServiceImpl<CourseVideoDao, CourseVideoEntity> implements CourseVideoService {

    @Autowired
    private CourseVideoDao courseVideoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<CourseVideoEntity> courseVideoEntityQueryWrapper = new QueryWrapper<>();
        Long courseId = (Long) params.get("courseId");
        Long fid = (Long) params.get("fId");
        courseVideoEntityQueryWrapper.eq( courseId!=null && !courseId.equals(0)  , "course_id", courseId);
        courseVideoEntityQueryWrapper.eq(fid!=null , "f_id", fid);
        courseVideoEntityQueryWrapper.orderByAsc("order_num");

        IPage<CourseVideoEntity> page = this.page(new Query<CourseVideoEntity>().getPage(params), courseVideoEntityQueryWrapper);

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryDetailPage(Map<String, Object> params) {
        QueryWrapper<CourseVideoEntity> courseVideoEntityQueryWrapper = new QueryWrapper<>();
        String courseId = (String) params.get("courseId");
        IPage<CourseVideoEntity> page = new Query<CourseVideoEntity>().getPage(params);
        IPage<CourseVideoEntity> courseVideoEntityIPage = courseVideoDao.queryPage(page, courseId);
        return new PageUtils(courseVideoEntityIPage);
    }


}
